<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Facades\Services\User\WeightService;

class Weight extends Model
{
    protected $table = 'weights';

    protected $fillable = [
    	'weight',
    	'wechat_user_id'
    ];

    protected $appends = [
    	'bmi'
    ];

    public function getBmiAttribute(){
        return $this->attributes['bmi']=WeightService::countBmi($this->attributes['weight'],WeightService::getHegithInSession());
    }

    public static $SQL_SELECT_TODAY = "SELECT * FROM `weights` WHERE date_format(weights.created_at,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') AND wechat_user_id = ?";

    public static $SQL_SELECT_ID_AND_TODAY = "SELECT * FROM `weights` WHERE `id` = ? AND wechat_user_id = ? AND date_format(weights.created_at,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d')";
}
